Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support json transaction files for debugging #483

Merged
merged 6 commits into from
Mar 6, 2025
Merged

Conversation

anshumankomawar
Copy link
Collaborator

@anshumankomawar anshumankomawar commented Feb 4, 2025

Summary

This PR introduces support for specifying the METAFILE_FORMAT using an environment variable.

Usage

The added metafile-format can be used like

$ METAFILE_FORMAT=json python ./my-script.py

supported values: json, msgpack[default]

Testing

make test

Regression Risk

If this is a bugfix, assess the risk of regression caused by this fix and steps taken to mitigate it.

Checklist

  • Unit tests covering the changes have been added

    • If this is a bugfix, regression tests have been added
  • E2E testing has been performed

@anshumankomawar anshumankomawar marked this pull request as ready for review February 5, 2025 04:35
Comment on lines +44 to +47
METAFILE_EXT = {
"json": ".json",
"msgpack": ".mpk",
}[METAFILE_FORMAT]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - that's a clever way to refactor this constant. :)

:return: Deserialized object from the metadata file.
"""
if format not in {"json", "msgpack"}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we add a new SUPPORTED_METAFILE_FORMATS constant to save this set in?

:return: Deserialized object from the metadata file.
"""
if format not in {"json", "msgpack"}:
raise ValueError(
f"Unsupported format '{format}'. Must be 'json' or 'msgpack'."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If we create the above constant, then we can just change this to something like:

Suggested change
f"Unsupported format '{format}'. Must be 'json' or 'msgpack'."
f"Unsupported format '{format}'. Supported formats include: {SUPPORTED_METAFILE_FORMATS}."

"""
if format not in {"json", "msgpack"}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit here about using a constant to save the supported formats.

@@ -37,6 +38,15 @@
False,
)

# CLI Args
METAFILE_FORMAT_KEY = "metafile-format"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to use standard environment variable casing here:

Suggested change
METAFILE_FORMAT_KEY = "metafile-format"
METAFILE_FORMAT_KEY = "METAFILE_FORMAT"



def env_bool(key: str, default: bool) -> bool:
cli_value = get_cli_arg(key)
Copy link
Member

@pdames pdames Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... since you can also set environment variables within the context of a single bash command, can we just let deltacat devs do that and not overload the environment variables here to either look for CLI args or environment variables?

(i.e., $ METAFILE_FORMAT=json python ./my-script.py)

We can then create a more formal/unified deltacat CLI experience within the context of a dedicated CLI application, similar to dev/deploy/aws/scripts/runner.py.

@pdames pdames merged commit 186d8d1 into 2.0 Mar 6, 2025
3 checks passed
anshumankomawar added a commit that referenced this pull request Mar 11, 2025
* chore: support json transaction files for debugging

* chore: support optional file format for metafiles

* refactor: remove uncessary print

* pr: remove cli arg dependency use os env instead

* fix: revert changes to common.py

---------

Signed-off-by: Patrick Ames <[email protected]>
Co-authored-by: Patrick Ames <[email protected]>
@anshumankomawar anshumankomawar deleted the dev/anshumankomawar branch March 12, 2025 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants